"use strict"
var call = require("../../../utils/request.js")
const app = getApp()
Page({
  data: {
    imgs: [],
    userInfo: '',
    birthday: '请选择日期',
    // cardid: '请输入身份证号',
    // phone: '请输入手机号'
    cardid: '',
    phone: '',
    items: [{
        name: '0',
        value: '全部房源'
      },
      {
        name: '1',
        value: '小时卡房源'
      },

    ],
    ftype: '',
    avatarUrl: 'https://www.yunzhuke.net/default.png'
  },

  onLoad: function (e) {
    if (wx.getStorageSync("uid")) {
      // this.userInfo = wx.getStorageSync("userInfo")
      var call = require("../../../utils/request.js")
      var url = 'getuser?uid=' + wx.getStorageSync("uid");
      call.getData(url, this.getuser, this.fail)

    } else {

      setTimeout(() => {
        wx.showToast({
          title: '请先授权登录',
          icon: "none",
        });
        setTimeout(() => {
          // wx.switchTab({
          //   url: '../mine/mine'
          // })
          wx.switchTab({
            url: '../../../pages/mine/mine',

          })

        }, 2000)
      }, 0);
    }

  },


  chooseImg: function (e) {
    var that = this
    wx.chooseImage({
      count: 1, // 默认9
      success(res) {
        const tempFilePaths = res.tempFilePaths

        wx.uploadFile({
          url: 'https://www.yunzhuke.net/api/data/getimg', //仅为示例，非真实的接口地址
          filePath: tempFilePaths[0],
          name: 'file',
          success(res2) {
            that.setData({
              avatarUrl: res2.data
            });
          }
        })
      }
    })
  },
  gohome: function (data) {
    wx.reLaunch({
      url: '../../../pages/index/index',
    })
  },
  getuser: function (e) {

    this.userInfo = e.data
    if (this.userInfo.nickName != 'undefined')
      this.setData({
        nickName: this.userInfo.nickName,
      })

    if (this.userInfo.avatarUrl) {
      if (this.userInfo.avatarUrl != 'undefined') {
        this.setData({
          avatarUrl: this.userInfo.avatarUrl,
        })
      }
    }


    if (this.userInfo.gender == 1) {

      this.setData({
        sex: '男',
      })
    } else {
      this.setData({
        sex: '女',
      })

    }

    if (this.userInfo.birthday) {

      this.setData({
        birthday: this.userInfo.birthday,
      })

    }

    if (this.userInfo.idcard) {
      this.setData({
        cardid: this.userInfo.idcard,
      })

    }


    if (this.userInfo.phone) {
      this.setData({
        phone: this.userInfo.phone,
      })

    }


    this.setData({
      ftype: this.userInfo.ftype,
    })

    if (this.userInfo.ftype == 1) {
      //小时卡
      this.setData({
        items: [{
            name: '0',
            value: '全部房源'
          },
          {
            name: '1',
            value: '小时卡房源',
            checked: 'true'
          },
        ]
      })

    } else {
      this.setData({
        items: [{
            name: '0',
            value: '全部房源',
            checked: 'true'
          },
          {
            name: '1',
            value: '小时卡房源'
          },
        ]
      })
    }


  },

  bbbc: function bbbc(e) {



  },


  starttime: function (e) {
    this.setData({
      starttime: e.detail.value
    })
  },

  loginForm: function (data) {
    var nickName = data.detail.value.nickName
    var cardid = data.detail.value.cardid
    var phone = data.detail.value.phone
    var birthday = this.data.birthday
    if (birthday == '请选择日期') {
      var birthday = ''
    }


    var call = require("../../../utils/request.js")
    var url = 'updateuser?uid=' + wx.getStorageSync("uid") + '&idcard=' + cardid + '&birthday=' + birthday +
      '&phone=' + phone + '&ftype=' + this.data.ftype + '&nickName=' + nickName + '&avatarUrl=' + this.data.avatarUrl;
    call.getData(url, this.updateuser, this.fail)



  },
  updateuser: function updateuser(e) {
    if (e.msg == 'success') {
      setTimeout(() => {
        wx.showToast({
          title: '更新成功',
          icon: "none",
        });
        setTimeout(() => {
          wx.switchTab({
            url: '../../../pages/mine/mine'
          })
        }, 2000)
      }, 0);
    } else {

      wx.showToast({
        title: '更新失败',
        icon: "none",
      });

    }


  },

  radioChange: function radioChange(e) {
    this.setData({
      ftype: e.detail.value
    })
  },

  DateChange: function DateChange(e) {
    this.setData({
      birthday: e.detail.value
    })

  },



  transData: function transData() {

  },
})